<script lang="ts" setup>
import { ref } from 'vue';
import { Search, Plus } from '@element-plus/icons-vue';
import http from '@/http';
import { ElMessage } from 'element-plus';


// 病例ID
const itemId = ref('');
// 检查项目
const inspectionItemsValue = ref('');
const inspectionItems = [
  '乙肝五项',
  '血常规',
  'CT',
  'X光'
];

// 添加检查结果
function checkInspectionItems(val: any) {
  inspectionItemsValue.value = val;
  http.get('/hcr/getHisCheckResult2?inspectionItems=' + inspectionItemsValue.value)
    .then((res) => {
      if (Array.isArray(res)) {
        inspectTableData.value = res;
      } else {
        ElMessage.error('请求返回的数据格式不正确，请检查！');
      }
    })
    .catch((error) => {
      ElMessage.error('请求失败，请检查网络或服务器状态：' + error);
    });
}

const inspectTableData = ref([]);

function queryAndCheckInformatio() {
  http.get('hcr/getHisCheckResult?id=' + itemId.value)
    .then((res) => {
      if (Array.isArray(res)) {
        inspectTableData.value = res;
      } else {
        ElMessage.error('请求返回的数据格式不正确，请检查！');
      }
    })
    .catch((error) => {
      ElMessage.error('请求失败，请检查网络或服务器状态：' + error);
    });
}


const handleEdit = (index: number, row) => {

  console.log(index);
};
</script>
<template>
  <el-row>
    <el-col :span="24">
      <span>检查项目：</span><el-segmented v-model="inspectionItemsValue" :options="inspectionItems"
        @change="checkInspectionItems" style="width: 400px;" />
    </el-col>
  </el-row>
  <br>
  <el-row>
    <el-col :span="24">
      <span>检查单号：</span><el-input v-model="itemId" style="width: 240px" />&nbsp;<el-button type="primary" :icon="Search"
        @click="queryAndCheckInformatio">查询</el-button>
    </el-col>
  </el-row>
  <br>

  <el-table :data="inspectTableData" border style="width: 100%;" empty-text="暂无数据，请确认你的检查单号或检查项目">
    <el-table-column property="itemId" label="检查单号" align="center" />
    <el-table-column property="checkItemName" label="项目名称" align="center" />
    <el-table-column property="patientName" label="患者名称" align="center" />
    <el-table-column label="检查状态" align="center">
      <template #default="scope">
        <span v-if="scope.row.resultStatus == 0">未录入检查结果</span>
        <span v-else>检测完成</span>
      </template>
    </el-table-column>
    <el-table-column property="resultMsg" label="检查结果" align="center" />
    <el-table-column property="createTime" label="创建时间" align="center" />
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button size="small" v-if="scope.row.resultStatus == 1" type="primary" @click="handleEdit(scope.$index, scope.row)">
          查看详细结果
        </el-button>
        <span v-else>无</span>
      </template>
    </el-table-column>
  </el-table>
</template>
<style scoped></style>
